package cn.gov.pbc.gd.credit.common.util;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropUtil 
{
	private static final Logger log = LoggerFactory.getLogger(PropUtil.class);
	
	static InputStream input = null;
	
	/**
	 * Please put your property file in resources directory. 
	 * @param fileName       property file name
	 * @return               Properties
	 * @throws IOException
	 */
	public static Properties getProperty(String fileName)
	{
		Properties prop = new Properties();
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		try
		{
			input = null;
			input = loader.getResourceAsStream(fileName);					
			prop.load(input);	
			input.close();
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
		}
		return prop;			
	}
		
	public static Properties loadProperties(String arg)
	{
		Properties prop = null;
		try
		{
			prop = new Properties();
			//first load default properties
			input = PropUtil.class.getClassLoader().getResourceAsStream(arg);
			if (input != null)
			{
				prop.load(input);
				input.close();			
//				prop.list(System.out);							
			}
			
			return prop;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
		}
		
		return prop;
	}	
	
}
